package com.fbank.p2p.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.druid.util.StringUtils;
import com.atzzgc.http.Student;
import com.fbank.p2p.service.CacheService;
import com.fbank.p2p.vo.CustomerModel;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;

@Controller
@RequestMapping("/cache")
public class Cache {
	/**
	* Logger for this class
	*/
	private static final Logger logger = Logger.getLogger(Cache.class);

	private static String appkey = "23791124";
	private static String url = "http://gw.api.taobao.com/router/rest";
	private static String secret = "3c701b6a87a16585bf92e2691b8bf98a";
	private static int i=0;
	@Autowired
	private CacheService cacheService;
	
	
	@RequestMapping("bb")
	public String testCache(Student student,HttpServletRequest request){
		logger.info("wwwww");
		if (logger.isDebugEnabled()) {
			logger.debug("testCache(HttpServletRequest) - start"); //$NON-NLS-1$
		}
		/*HttpSession session = request.getSession();
		System.out.println(session.toString());
		System.out.println("开始");
		cacheService.testCache();
		System.out.println("结束");
		CacheUtils.put("11",session.toString() );
		CacheUtils.put("12","111" );
		Object object = CacheUtils.get("11");
		Object object2 = CacheUtils.get("12");
		CacheManager cacheManager = CacheUtils.getCacheManager();
		System.out.println(cacheManager);
		System.out.println((String)object);
		System.out.println((String)object2);
*/
		if (logger.isDebugEnabled()) {
			logger.debug("testCache(HttpServletRequest) - end"); //$NON-NLS-1$
		}
		
		if (!StringUtils.isEmpty(student.getMoblie())&& !StringUtils.isEmpty(student.getName())) {
			
			
			TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
			AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
			req.setExtend("123456");
			req.setSmsType("normal");
			req.setSmsFreeSignName("免费班车");
			req.setSmsParamString("{\"name\":\""+student.getName()+"\"}");
			req.setRecNum(student.getMoblie());
			req.setSmsTemplateCode("SMS_64500004");
			AlibabaAliqinFcSmsNumSendResponse rsp;
			
			try {
				rsp = client.execute(req);
				System.out.println(rsp.getBody());
			} catch (ApiException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		}
		
		return "success";
		
		
		
	}
	
	@RequestMapping("thread")
	public String testThread(CustomerModel customerModel ,HttpServletRequest request){
		i++;
		System.out.println(i);
		
		
		return "success";
	}
	
}
